﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightCountDownTimer.Utils
{
    /// <summary>
    /// This class was created to download content of file from provided url.
    /// </summary>
    public class FileReader
    {
        public event EventHandler FileDownloaded;

        public void ReadFileAsync(string fileUrl)
        {
            WebClient client = new WebClient();
            client.DownloadStringAsync(new Uri(fileUrl));
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
        }

        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null & FileDownloaded != null)
            {
                FileDownloaded(this, e);
            }
        }
    }
}
